function isEmpty(param){
	//判断参数是否为空
			if(null==param){
				return true;
			}else if('null'==param){
				return true;
			}else if(undefined == param){
				return true;
			}else if('undefined' == param){
				return true;
			}else if(''==param){
				return true;
			}else{
				return false;
			}
		}
function onQxfl(ygh){
	//判断是否具有访问权限,参数:判断依据\URL roleParam值
	//返回:权限不足-'false';权限满足-插入后台的参数值
		if(isEmpty(roleParam)&&isEmpty(ygh)){
			return "";
		}else if(isEmpty(roleParam)&&!isEmpty(ygh)){
			return ygh;
		}else if(!isEmpty(roleParam)&&isEmpty(ygh)){
			return roleParam;
		}else{
			var roleParams = roleParam.split(",");
			for (var i = 0; i < roleParams.length; i++) {
				var param = roleParams[i];
				var param_l = param.toString().length;
				if (ygh.length >= param_l&& param == ygh.substring(0, param_l)) {
					return ygh;
				}
			}
			return 'false';
		}
	}
function getPostData(id,qxName) {
	//获取搜索表单值的map集合
	//如权限Name不为空,需判断用户权限
	//返回:权限不足-'false';否则,map集合
	var formData = $(id).serializeArray();
	var postData = {};
	var flag = true;
	$.each(formData, function() {
				postData[this.name] = this.value;
				if (!isEmpty(qxName)&&this.name == qxName) {
					postData[this.name] = onQxfl(this.value);
					if ('false' == postData[this.name]) {
						flag = false;
					}
				}
			});
	if (flag) {
		return postData;
	} else {
		return 'false';
	}
}
function initGrid(param) {
	//创建grid模板
	var gridId = param.gridId;//grid容器id(#jQGrid)
	var url = param.url;//grid提交地址
	var colModel = param.colModel;//列属性
	var isSum = param.isSum;//是否有汇总行
	$(gridId).jqGrid({
		url : url,
		datatype : "local",
		mtype : 'post',
		modal : true,
		colModel : colModel,
		viewrecords : true,
		rowNum : 50,
		pager : gridId + 'Pager',
		shrinkToFit : false,// 列宽 不自动
		multiselect : true,
		multiboxonly : true,
		beforeSelectRow : function(rowid, e) {
			$(this).jqGrid('resetSelection');
			return (true);
		}, // 实现复选框单选
		onSelectAll : function(aRowids, status) {
			$(this).jqGrid('resetSelection');
		}, // 实现头部复选框,无效
		autowidth : true,
		height : isSum ? ($(window).height() - 105) : ($(window).height() - 85), // 屏幕高度-86-汇总栏20
		rownumbers : true,
		prmNames : {
			rows : 'limit'
		},
		jsonReader : {
			id : "ID",
			root : "data",
			records : 'total',
			total : 'totalPage',
			repeatitems : true
		},
		footerrow : isSum,// 合计行,无汇总需删除
		userDataOnFooter : isSum
	});
}

function reloadGrid(gridId,formId,qxName,qxLable) {
	//gridId:grid容器id(带#,如#jQGrid)
	//formId:查询form表单id(带#)
	//qxName:检查权限的文本框name名
	//qxLable:检查权限的文本框显示名字
	var postData = getPostData(formId,qxName);
	if (postData == 'false') {
		setAlert("权限不足,"+qxLable+"必须以" + roleParam.split(',').join('或') + "开头");
	} else {
		$(gridId).jqGrid('setGridParam', {
					postData : postData,
					datatype : 'json'
				}).trigger("reloadGrid");
	}
}
function onLoadExcel(url,params){
	//下载Excel
	var param=new Array();
	for(var key in params){
		param.push(key+"="+params[key]);
	};
	window.open(url+"?"+param.join('&'));
}


function setAlert(msg) {
// 弹出提示框
	$("#dialog_alert").empty();
	$("#dialog_alert").append("<label>" + msg + "</label>");
	$("#dialog_alert").dialog({
				modal : true,
				title:'提示',
				buttons : {
					"确定" : function() {
						$(this).dialog("close");
					}
				}
			});
}